<template>
    <div>
        <el-drawer :title="title" visible @close="$emit('close');$emit('load')" size="1200px" :wrapperClosable="false">
            <div class="add-main box" v-loading="loading">
                <!-- <div class="btn-con">
                    <el-button type="primary" size="small" icon="el-icon-circle-check" @click.native.prevent="submit()" :disabled="loading">提交
                    </el-button>
                </div> -->
                <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
                    <el-tab-pane label="基本信息" name="first">
                        <basic ref="basic" :handleShow="handleShow" :customerId="id" @update="update" @getCustomerId="getCustomerId" />
                    </el-tab-pane>
                    <el-tab-pane label="健康信息" name="second" :disabled="!id">
                        <healthy ref="healthy" :handleShow="handleShow" :customerId="id" @update="update" />
                    </el-tab-pane>
                    <el-tab-pane label="家属信息" name="third" :disabled="!id" v-if="pageType!='archives'">
                        <family ref="family" :type="handleShow" :customerId="id" />
                    </el-tab-pane>
                    <el-tab-pane label="入院登记" name="fourth" :disabled="!id" v-if="pageType!='archives'">
                        <hospital ref="hospital" :handleShow="handleShow" :customerId="id" @close="$emit('close')" @load="$emit('load')" />
                    </el-tab-pane>
                </el-tabs>
            </div>
        </el-drawer>
    </div>
</template>
<script>
import basic from "./detail/basic"
import healthy from "./detail/healthy"
import family from "./detail/family"
import hospital from "./detail/hospital"


import throttle from 'lodash.throttle'
// import { setHospToBasics, setHospToHealthy } from "@/api/marketing/admit"
export default {
    name: '',
    props: {
        title: String,
        handleShow: {
            type: String, //add新增edit编辑
            default: ""
        },
        customerId: String,
        pageType: {
            type: String,
            default: ""
        },
    },
    components: {
        basic,
        healthy,
        family,
        hospital
    },
    data() {
        return {
            loading: false,
            activeName: 'first',
            curLine: -1,
            tabType: 1,// 1基本信息2健康信息3家属信息
            id: this.customerId,
        }
    },
    created() {
    },
    methods: {
        // 列表切换
        handleClick(tab, event) {
            if (tab.name == 'first') {
                this.tabType = 1
                this.curLine = -1
                this.$refs.basic.getDetail()
            } else if (tab.name == 'second') {
                this.tabType = 2
                this.$refs.healthy.form = {}
                this.$refs.healthy.getDetail()
                this.curLine = -1
            } else if (tab.name == 'third') {
                this.tabType = 3
                this.curLine = -1
            } else if (tab.name == 'fourth') {
                this.tabType = 4
                this.curLine = -1
                this.$refs.hospital.getDetail()
            }
        },
        update(parm) {
            this.activeName = parm
        },
        getCustomerId(val) {
            this.id = val
        },
        submit: throttle(function () {
            // let fun1 = new Promise((resolve, reject) => {
            //     this.$refs.basic.$refs.form.validate((valid) => {
            //         if (valid) {
            //             resolve();
            //         } else reject();
            //     });
            // });
            // let fun2 = new Promise((resolve, reject) => {
            //     this.$refs.healthy.$refs.form.validate((valid) => {
            //         if (valid) {
            //             resolve();
            //         } else reject();
            //     });
            // });
            // Promise.all([fun1]).then(data => {
            //     let funk = [
            //         setHospToBasics(this.$refs.basic.form),
            //         setHospToHealthy(this.$refs.healthy.form),
            //     ]
            //     Promise.all(funk).then(res => {
            //         this.msgSuccess("操作成功！");
            //         this.$emit('close')
            //         this.loading = false;
            //         this.$emit('load')
            //     })
            // })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
/deep/.el-tabs--border-card {
    .topBtn {
        position: fixed;
        top: 780px;
        z-index: 999999;
    }
}
</style>

